/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package frm.billingAndPaymentProcessing.session;

import frm.billingAndPaymentProcessing.entity.IncomingBillEntity;

import java.util.List;
import javax.ejb.Stateless;
import javax.ejb.LocalBean;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author xhx
 */
@Stateless
@LocalBean
public class IncomingBillSessionBean {
 @PersistenceContext
    private EntityManager em;

    public void createIncomingBill(IncomingBillEntity incomingBillEntity) {
        em.persist(incomingBillEntity);
    }

    public IncomingBillEntity getIncomingBillById(Long incomingBillId) {
        return em.find(IncomingBillEntity.class, incomingBillId);
    }

    public List<IncomingBillEntity> getAllIncomingBills() {
        Query query = em.createQuery("SELECT u FROM IncomingBillEntity u where u.abolished=0");
        return query.getResultList();
    }
    public List<IncomingBillEntity>getAbolishedBills(){
        Query query = em.createQuery("SELECT u FROM IncomingBillEntity u where u.abolished =1");
        return query.getResultList();
    }
    public boolean containBillId(Long billId){
        Query query = em.createQuery("SELECT u FROM IncomingBillEntity u where u.billId =:dd");
        query.setParameter("dd", billId);
        boolean contain = false;
        if(query.getResultList().size()>0)
            contain = true;
        return contain;
    }
    public void saveChanges(IncomingBillEntity incomingBillEntity) {
        em.merge(incomingBillEntity);
    }
    public void removeIncomingBill(IncomingBillEntity incomingBillEntity){
        
        em.remove(incomingBillEntity);
        
}
    
}
